import logging
import time

import pymysql
import requests
from bs4 import BeautifulSoup

from my_rss import build_dblp_json_api_url, fetch_rss_content
from scholar import get_paper_abstract


def update_dblp_info(result):
    conn = pymysql.connect(
        host='lib.gorio.top',
        port=13306,
        user='root',
        password='t4hf647e',
        database='rss'
    )
    cursor = conn.cursor(pymysql.cursors.DictCursor)
    for site_name in result.keys():
        for conf in result[site_name]:
            if "conf" in conf['link']:
                sql_check = "SELECT COUNT(*) as 'co' FROM `rss`.`conferences` WHERE `link` = %s"
                sql_update = "UPDATE `rss`.`conferences` SET `pubDate` = %s WHERE `link` = %s"
                sql_insert = "INSERT INTO `rss`.`conferences` (`conference_name`, `link`, `title`, `pubDate`) VALUES (%s, %s, %s, %s)"
            elif "journals" in conf['link']:
                sql_check = "SELECT COUNT(*) as 'co' FROM `rss`.`journals` WHERE `links` = %s"
                sql_update = "UPDATE `rss`.`journals` SET `pubDate` = %s WHERE `links` = %s"
                sql_insert = "INSERT INTO `rss`.`journals` (`journals_name`, `links`, `title`, `pubDate`) VALUES (%s, %s, %s, %s)"
            else:
                continue

            cursor.execute(sql_check, (conf['link'],))
            exists = cursor.fetchone()['co'] > 0

            if exists:
                cursor.execute(sql_update, (conf['pubDate'], conf['link']))

                sql = """
                SELECT 
                    CASE 
                        WHEN pubDate IS NULL THEN 0
                        WHEN pubDate = (
                            SELECT MAX(pubDate) 
                            FROM conferences 
                            WHERE conference_name = (SELECT conference_name FROM conferences WHERE link = %s)
                        ) THEN 1
                        ELSE 0
                    END AS is_latest
                FROM conferences
                WHERE link = %s;
                """

                cursor.execute(sql, (conf['link'], conf['link']))
                res = cursor.fetchone()
                if res:
                    is_latest = res['is_latest']
                    print(f"{conf['title']}'s is_latest: {is_latest}")
                else:
                    print(f"{conf['title']}'s res error")



            else:
                cursor.execute(sql_insert, (site_name, conf['link'], conf['title'], conf['pubDate']))

            conn.commit()
            print(f"Processed paper: {conf['title']} from {site_name}")
    # for site_name in result.keys():
    #     for conf in result[site_name]:
    #         if "conf" in conf['link']:
    #             sql = "UPDATE `rss`.`conferences` SET `pubDate` = %s WHERE (rss.conferences.`link` = %s)"
    #
    #         elif "journals" in conf['link']:
    #             sql = "UPDATE `rss`.`journals` SET `pubDate` = %s WHERE (rss.journals.`links` = %s)"
    #
    #         cursor.execute(sql, (conf['pubDate'], conf['link']))
    #         conn.commit()
    #         print(f"Inserted paper: {conf['title']} from {site_name}")

    cursor.close()
    conn.close()
    print("Done")


if __name__ == '__main__':
    logging.basicConfig(
        level=logging.INFO,
        format='[%(asctime)s] [%(levelname)s] %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S'
    )
    sites = [
        # {'site_name': "ASIACRYPT", 'rss_url': "https://dblp.org/feed/streams/conf/asiacrypt.rss"},
        #      {'site_name': "CCS", 'rss_url': "https://dblp.org/feed/streams/conf/ccs.rss"},
        #      {'site_name': "CRYPTO", "rss_url": "https://dblp.org/feed/streams/conf/crypto.rss"},
        #      {'site_name': "EUROCRYPT", "rss_url": "https://dblp.org/feed/streams/conf/eurocrypt.rss"},
        #      {'site_name': "INFOCOM", "rss_url": "https://dblp.org/feed/streams/conf/infocom.rss"},
        #      {'site_name': "MobiCom", "rss_url": "https://dblp.org/feed/streams/conf/mobicom.rss"},
        #      {'site_name': "NDSS", "rss_url": "https://dblp.org/feed/streams/conf/ndss.rss"},
        #      {'site_name': "NSDI", "rss_url": "https://dblp.org/feed/streams/conf/nsdi.rss"},
        #      {'site_name': "SIGCOMM", "rss_url": "https://dblp.org/feed/streams/conf/sigcomm.rss"},
        #      {'site_name': "S & P", "rss_url": "https://dblp.org/feed/streams/conf/sp.rss"},
        #      {'site_name': "USENIX Security", "rss_url": "https://dblp.org/feed/streams/conf/uss.rss"},
             {'site_name': "J. Cryptol", "rss_url": "https://dblp.org/feed/streams/journals/joc.rss"},
             {'site_name': "TOPS", "rss_url": "https://dblp.org/feed/streams/journals/tissec.rss"},
             {'site_name': "TOPS", "rss_url": "https://dblp.org/feed/streams/journals/tissec.rss"},
             {'site_name': "Computers & Security", "rss_url": "https://dblp.org/feed/streams/journals/compsec.rss"},
             {'site_name': "Designs, Codes and Cryptography", "rss_url": "https://dblp.org/feed/streams/journals/dcc.rss"},
             {'site_name': "JCS", "rss_url": "https://dblp.org/feed/streams/journals/jcs.rss"},

             ]
    result = fetch_rss_content(sites)
    print(result)
    # print(result.keys())
    # {'CRYPTO': [{'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2024-4.html',
    # 'title': 'CRYPTO (4) 2024', 'pubDate': 'Wed, 28 Aug 2024 01:00:00 +0200'},
    # {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2024-5.html', 'title': 'CRYPTO (5) 2024', 'pubDate': 'Wed, 28 Aug 2024 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2024-6.html', 'title': 'CRYPTO (6) 2024', 'pubDate': 'Wed, 28 Aug 2024 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2024-7.html', 'title': 'CRYPTO (7) 2024', 'pubDate': 'Wed, 28 Aug 2024 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2024-1.html', 'title': 'CRYPTO (1) 2024', 'pubDate': 'Tue, 20 Aug 2024 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2024-10.html', 'title': 'CRYPTO (10) 2024', 'pubDate': 'Tue, 20 Aug 2024 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2024-2.html', 'title': 'CRYPTO (2) 2024', 'pubDate': 'Tue, 20 Aug 2024 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2024-3.html', 'title': 'CRYPTO (3) 2024', 'pubDate': 'Tue, 20 Aug 2024 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2024-8.html', 'title': 'CRYPTO (8) 2024', 'pubDate': 'Tue, 20 Aug 2024 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2024-9.html', 'title': 'CRYPTO (9) 2024', 'pubDate': 'Tue, 20 Aug 2024 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2023-1.html', 'title': 'CRYPTO (1) 2023', 'pubDate': 'Mon, 14 Aug 2023 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2023-2.html', 'title': 'CRYPTO (2) 2023', 'pubDate': 'Mon, 14 Aug 2023 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2023-3.html', 'title': 'CRYPTO (3) 2023', 'pubDate': 'Mon, 14 Aug 2023 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2023-4.html', 'title': 'CRYPTO (4) 2023', 'pubDate': 'Mon, 14 Aug 2023 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2023-5.html', 'title': 'CRYPTO (5) 2023', 'pubDate': 'Mon, 14 Aug 2023 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2022-1.html', 'title': 'CRYPTO (1) 2022', 'pubDate': 'Wed, 19 Oct 2022 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2022-2.html', 'title': 'CRYPTO (2) 2022', 'pubDate': 'Wed, 19 Oct 2022 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2022-3.html', 'title': 'CRYPTO (3) 2022', 'pubDate': 'Wed, 19 Oct 2022 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2022-4.html', 'title': 'CRYPTO (4) 2022', 'pubDate': 'Wed, 19 Oct 2022 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2021-1.html', 'title': 'CRYPTO (1) 2021', 'pubDate': 'Mon, 16 Aug 2021 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2021-2.html', 'title': 'CRYPTO (2) 2021', 'pubDate': 'Mon, 16 Aug 2021 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2021-3.html', 'title': 'CRYPTO (3) 2021', 'pubDate': 'Mon, 16 Aug 2021 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2021-4.html', 'title': 'CRYPTO (4) 2021', 'pubDate': 'Mon, 16 Aug 2021 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2020-2.html', 'title': 'CRYPTO (2) 2020', 'pubDate': 'Thu, 13 Aug 2020 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2020-1.html', 'title': 'CRYPTO (1) 2020', 'pubDate': 'Wed, 12 Aug 2020 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2020-3.html', 'title': 'CRYPTO (3) 2020', 'pubDate': 'Wed, 12 Aug 2020 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2019-1.html', 'title': 'CRYPTO (1) 2019', 'pubDate': 'Fri, 09 Aug 2019 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2019-2.html', 'title': 'CRYPTO (2) 2019', 'pubDate': 'Fri, 09 Aug 2019 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2019-3.html', 'title': 'CRYPTO (3) 2019', 'pubDate': 'Fri, 09 Aug 2019 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2018-1.html', 'title': 'CRYPTO (1) 2018', 'pubDate': 'Mon, 13 Aug 2018 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2018-2.html', 'title': 'CRYPTO (2) 2018', 'pubDate': 'Mon, 13 Aug 2018 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2018-3.html', 'title': 'CRYPTO (3) 2018', 'pubDate': 'Mon, 13 Aug 2018 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2017-1.html', 'title': 'CRYPTO (1) 2017', 'pubDate': 'Mon, 14 Aug 2017 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2017-2.html', 'title': 'CRYPTO (2) 2017', 'pubDate': 'Mon, 14 Aug 2017 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2017-3.html', 'title': 'CRYPTO (3) 2017', 'pubDate': 'Mon, 14 Aug 2017 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2016-1.html', 'title': 'CRYPTO (1) 2016', 'pubDate': 'Wed, 27 Jul 2016 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2016-2.html', 'title': 'CRYPTO (2) 2016', 'pubDate': 'Wed, 27 Jul 2016 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2016-3.html', 'title': 'CRYPTO (3) 2016', 'pubDate': 'Wed, 27 Jul 2016 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2015-1.html', 'title': 'CRYPTO (1) 2015', 'pubDate': 'Mon, 03 Aug 2015 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2015-2.html', 'title': 'CRYPTO (2) 2015', 'pubDate': 'Mon, 03 Aug 2015 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2014-1.html', 'title': 'CRYPTO (1) 2014', 'pubDate': 'Tue, 15 Jul 2014 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2014-2.html', 'title': 'CRYPTO (2) 2014', 'pubDate': 'Tue, 15 Jul 2014 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2013-1.html', 'title': 'CRYPTO (1) 2013', 'pubDate': 'Wed, 21 Aug 2013 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2013-2.html', 'title': 'CRYPTO (2) 2013', 'pubDate': 'Wed, 21 Aug 2013 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2012.html', 'title': 'CRYPTO 2012', 'pubDate': 'Mon, 13 Aug 2012 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2011.html', 'title': 'CRYPTO 2011', 'pubDate': 'Mon, 15 Aug 2011 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2010.html', 'title': 'CRYPTO 2010', 'pubDate': 'Tue, 17 Aug 2010 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2009.html', 'title': 'CRYPTO 2009', 'pubDate': 'Wed, 07 Oct 2009 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2008.html', 'title': 'CRYPTO 2008', 'pubDate': 'Tue, 26 Aug 2008 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2007.html', 'title': 'CRYPTO 2007', 'pubDate': 'Tue, 21 Aug 2007 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2006.html', 'title': 'CRYPTO 2006', 'pubDate': 'Thu, 14 Dec 2006 00:00:00 +0100'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2005.html', 'title': 'CRYPTO 2005', 'pubDate': 'Fri, 04 Nov 2005 00:00:00 +0100'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2004.html', 'title': 'CRYPTO 2004', 'pubDate': 'Tue, 11 Jan 2005 00:00:00 +0100'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2003.html', 'title': 'CRYPTO 2003', 'pubDate': 'Wed, 07 Jan 2004 00:00:00 +0100'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2002.html', 'title': 'CRYPTO 2002', 'pubDate': 'Tue, 22 Oct 2002 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2001.html', 'title': 'CRYPTO 2001', 'pubDate': 'Tue, 14 Aug 2001 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto2000.html', 'title': 'CRYPTO 2000', 'pubDate': 'Mon, 14 Aug 2000 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto99.html', 'title': 'CRYPTO 1999', 'pubDate': 'Mon, 20 Sep 1999 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto86.html', 'title': 'CRYPTO 1986', 'pubDate': 'Tue, 29 Jun 1999 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto81.html', 'title': 'CRYPTO 1981', 'pubDate': 'Thu, 24 Jun 1999 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto82.html', 'title': 'CRYPTO 1982', 'pubDate': 'Fri, 27 Nov 1998 00:00:00 +0100'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto98.html', 'title': 'CRYPTO 1998', 'pubDate': 'Mon, 19 Oct 1998 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto84.html', 'title': 'CRYPTO 1984', 'pubDate': 'Fri, 17 Jul 1998 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto87.html', 'title': 'CRYPTO 1987', 'pubDate': 'Tue, 14 Jul 1998 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto83.html', 'title': 'CRYPTO 1983', 'pubDate': 'Mon, 13 Jul 1998 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto88.html', 'title': 'CRYPTO 1988', 'pubDate': 'Thu, 28 May 1998 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto89.html', 'title': 'CRYPTO 1989', 'pubDate': 'Tue, 12 May 1998 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto90.html', 'title': 'CRYPTO 1990', 'pubDate': 'Thu, 30 Apr 1998 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto91.html', 'title': 'CRYPTO 1991', 'pubDate': 'Wed, 29 Apr 1998 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto97.html', 'title': 'CRYPTO 1997', 'pubDate': 'Wed, 29 Oct 1997 00:00:00 +0100'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto85.html', 'title': 'CRYPTO 1985', 'pubDate': 'Thu, 17 Apr 1997 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto93.html', 'title': 'CRYPTO 1993', 'pubDate': 'Wed, 16 Apr 1997 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto94.html', 'title': 'CRYPTO 1994', 'pubDate': 'Mon, 14 Apr 1997 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto96.html', 'title': 'CRYPTO 1996', 'pubDate': 'Fri, 11 Apr 1997 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto92.html', 'title': 'CRYPTO 1992', 'pubDate': 'Thu, 10 Apr 1997 01:00:00 +0200'}, {'conference_name': 'CRYPTO', 'link': 'https://dblp.org/db/conf/crypto/crypto95.html', 'title': 'CRYPTO 1995', 'pubDate': 'Fri, 21 Feb 1997 00:00:00 +0100'}], 'EUROCRYPT': [{'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2025-1.html', 'title': 'EUROCRYPT (1) 2025', 'pubDate': 'Wed, 07 May 2025 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2025-2.html', 'title': 'EUROCRYPT (2) 2025', 'pubDate': 'Wed, 07 May 2025 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2025-3.html', 'title': 'EUROCRYPT (3) 2025', 'pubDate': 'Wed, 07 May 2025 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2025-4.html', 'title': 'EUROCRYPT (4) 2025', 'pubDate': 'Wed, 07 May 2025 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2025-5.html', 'title': 'EUROCRYPT (5) 2025', 'pubDate': 'Wed, 07 May 2025 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2025-6.html', 'title': 'EUROCRYPT (6) 2025', 'pubDate': 'Wed, 07 May 2025 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2025-7.html', 'title': 'EUROCRYPT (7) 2025', 'pubDate': 'Wed, 07 May 2025 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2025-8.html', 'title': 'EUROCRYPT (8) 2025', 'pubDate': 'Wed, 07 May 2025 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2024-2.html', 'title': 'EUROCRYPT (2) 2024', 'pubDate': 'Thu, 16 May 2024 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2024-1.html', 'title': 'EUROCRYPT (1) 2024', 'pubDate': 'Thu, 09 May 2024 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2024-3.html', 'title': 'EUROCRYPT (3) 2024', 'pubDate': 'Thu, 09 May 2024 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2024-4.html', 'title': 'EUROCRYPT (4) 2024', 'pubDate': 'Thu, 09 May 2024 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2024-5.html', 'title': 'EUROCRYPT (5) 2024', 'pubDate': 'Thu, 09 May 2024 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2024-6.html', 'title': 'EUROCRYPT (6) 2024', 'pubDate': 'Thu, 09 May 2024 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2023-1.html', 'title': 'EUROCRYPT (1) 2023', 'pubDate': 'Thu, 20 Apr 2023 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2023-2.html', 'title': 'EUROCRYPT (2) 2023', 'pubDate': 'Thu, 20 Apr 2023 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2023-3.html', 'title': 'EUROCRYPT (3) 2023', 'pubDate': 'Thu, 20 Apr 2023 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2023-4.html', 'title': 'EUROCRYPT (4) 2023', 'pubDate': 'Thu, 20 Apr 2023 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2023-5.html', 'title': 'EUROCRYPT (5) 2023', 'pubDate': 'Thu, 20 Apr 2023 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2022-1.html', 'title': 'EUROCRYPT (1) 2022', 'pubDate': 'Tue, 31 May 2022 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2022-2.html', 'title': 'EUROCRYPT (2) 2022', 'pubDate': 'Tue, 31 May 2022 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2022-3.html', 'title': 'EUROCRYPT (3) 2022', 'pubDate': 'Tue, 31 May 2022 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2021-1.html', 'title': 'EUROCRYPT (1) 2021', 'pubDate': 'Wed, 16 Jun 2021 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2021-2.html', 'title': 'EUROCRYPT (2) 2021', 'pubDate': 'Wed, 16 Jun 2021 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2021-3.html', 'title': 'EUROCRYPT (3) 2021', 'pubDate': 'Wed, 16 Jun 2021 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2020-1.html', 'title': 'EUROCRYPT (1) 2020', 'pubDate': 'Mon, 04 May 2020 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2020-2.html', 'title': 'EUROCRYPT (2) 2020', 'pubDate': 'Mon, 04 May 2020 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2020-3.html', 'title': 'EUROCRYPT (3) 2020', 'pubDate': 'Mon, 04 May 2020 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2019-1.html', 'title': 'EUROCRYPT (1) 2019', 'pubDate': 'Tue, 14 May 2019 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2019-2.html', 'title': 'EUROCRYPT (2) 2019', 'pubDate': 'Tue, 14 May 2019 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2019-3.html', 'title': 'EUROCRYPT (3) 2019', 'pubDate': 'Tue, 14 May 2019 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2018-1.html', 'title': 'EUROCRYPT (1) 2018', 'pubDate': 'Mon, 16 Apr 2018 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2018-2.html', 'title': 'EUROCRYPT (2) 2018', 'pubDate': 'Mon, 16 Apr 2018 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2018-3.html', 'title': 'EUROCRYPT (3) 2018', 'pubDate': 'Mon, 16 Apr 2018 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2017-1.html', 'title': 'EUROCRYPT (1) 2017', 'pubDate': 'Mon, 10 Apr 2017 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2017-2.html', 'title': 'EUROCRYPT (2) 2017', 'pubDate': 'Mon, 10 Apr 2017 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2017-3.html', 'title': 'EUROCRYPT (3) 2017', 'pubDate': 'Mon, 10 Apr 2017 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2016-1.html', 'title': 'EUROCRYPT (1) 2016', 'pubDate': 'Fri, 29 Apr 2016 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2016-2.html', 'title': 'EUROCRYPT (2) 2016', 'pubDate': 'Fri, 29 Apr 2016 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2015-1.html', 'title': 'EUROCRYPT (1) 2015', 'pubDate': 'Tue, 14 Apr 2015 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2015-2.html', 'title': 'EUROCRYPT (2) 2015', 'pubDate': 'Tue, 14 Apr 2015 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2014.html', 'title': 'EUROCRYPT 2014', 'pubDate': 'Fri, 02 May 2014 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2013.html', 'title': 'EUROCRYPT 2013', 'pubDate': 'Wed, 22 May 2013 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2012.html', 'title': 'EUROCRYPT 2012', 'pubDate': 'Mon, 16 Apr 2012 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2011.html', 'title': 'EUROCRYPT 2011', 'pubDate': 'Thu, 05 May 2011 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2010.html', 'title': 'EUROCRYPT 2010', 'pubDate': 'Tue, 08 Jun 2010 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2009.html', 'title': 'EUROCRYPT 2009', 'pubDate': 'Thu, 23 Apr 2009 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2008.html', 'title': 'EUROCRYPT 2008', 'pubDate': 'Tue, 15 Apr 2008 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2007.html', 'title': 'EUROCRYPT 2007', 'pubDate': 'Mon, 25 Jun 2007 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2006.html', 'title': 'EUROCRYPT 2006', 'pubDate': 'Wed, 05 Jul 2006 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2005.html', 'title': 'EUROCRYPT 2005', 'pubDate': 'Fri, 20 May 2005 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2004.html', 'title': 'EUROCRYPT 2004', 'pubDate': 'Tue, 20 Apr 2004 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2003.html', 'title': 'EUROCRYPT 2003', 'pubDate': 'Thu, 15 May 2003 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2002.html', 'title': 'EUROCRYPT 2002', 'pubDate': 'Tue, 30 Apr 2002 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2001.html', 'title': 'EUROCRYPT 2001', 'pubDate': 'Fri, 27 Apr 2001 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt2000.html', 'title': 'EUROCRYPT 2000', 'pubDate': 'Fri, 11 Aug 2000 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt86.html', 'title': 'EUROCRYPT 1986', 'pubDate': 'Wed, 30 Jun 1999 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt82.html', 'title': 'EUROCRYPT 1982', 'pubDate': 'Tue, 29 Jun 1999 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt89.html', 'title': 'EUROCRYPT 1989', 'pubDate': 'Tue, 25 May 1999 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt88.html', 'title': 'EUROCRYPT 1988', 'pubDate': 'Mon, 03 May 1999 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt99.html', 'title': 'EUROCRYPT 1999', 'pubDate': 'Tue, 20 Apr 1999 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt85.html', 'title': 'EUROCRYPT 1985', 'pubDate': 'Mon, 12 Apr 1999 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt87.html', 'title': 'EUROCRYPT 1987', 'pubDate': 'Wed, 07 Apr 1999 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt84.html', 'title': 'EUROCRYPT 1984', 'pubDate': 'Mon, 20 Jul 1998 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt98.html', 'title': 'EUROCRYPT 1998', 'pubDate': 'Mon, 20 Jul 1998 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt90.html', 'title': 'EUROCRYPT 1990', 'pubDate': 'Wed, 15 Jul 1998 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt91.html', 'title': 'EUROCRYPT 1991', 'pubDate': 'Wed, 13 Aug 1997 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt97.html', 'title': 'EUROCRYPT 1997', 'pubDate': 'Mon, 21 Jul 1997 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt92.html', 'title': 'EUROCRYPT 1992', 'pubDate': 'Wed, 11 Jun 1997 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt93.html', 'title': 'EUROCRYPT 1993', 'pubDate': 'Mon, 05 May 1997 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt95.html', 'title': 'EUROCRYPT 1995', 'pubDate': 'Fri, 02 May 1997 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt94.html', 'title': 'EUROCRYPT 1994', 'pubDate': 'Thu, 10 Apr 1997 01:00:00 +0200'}, {'conference_name': 'EUROCRYPT', 'link': 'https://dblp.org/db/conf/eurocrypt/eurocrypt96.html', 'title': 'EUROCRYPT 1996', 'pubDate': 'Mon, 24 Feb 1997 00:00:00 +0100'}]}
    update_dblp_info(result)
    # conn = pymysql.connect(
    #     host='lib.gorio.top',
    #     port=17023,
    #     user='root',
    #     password='t4hf647e',
    #     database='rss'
    # )
    # cursor = conn.cursor(pymysql.cursors.DictCursor)
    # sql = "insert into conferences (conference_name, title, link) values (%s, %s, %s)"
    # # # cursor.execute(sql, (sites, papers['title'], papers['link'], papers['summary'], papers['authors']))
    # # # conn.commit()
    # for conference_name in result.keys():
    #     print(conference_name)
    #     # cursor.executemany(sql, (for [conference_name, title,link] in zip(conference_name, result[conference_name])))
    #     # conn.commit()
    #     for paper in result[conference_name]:
    #         cursor.execute(sql, (conference_name, paper['title'], paper['link']))
    #         conn.commit()
    #         print(f"Inserted paper: {paper['title']} from {conference_name}")
    # cursor.close()
    # conn.close()
    # print("Done")
    # url = "https://dblp.org/db/conf/sp/sp2024.html"
    # url = build_dblp_json_api_url(url)
    # # print(url)
    #
    #
    # response = requests.get(url)
    # data = response.json()
    # # print(data)
    # # result --> hits --> hit -- authors -- author -- text      --> (authors)
    # #                        |-- title                          --> (title)
    # #                        |-- year                           --> (published)
    # #                        |-- ee                             --> (link)
    # #                        get_paper_abstract(title)          --> (summary)
    #
    #
    # for hit in data["result"]["hits"]['hit']:
    #     info = hit['info']
    #     print("title:" + info['title'])
    #     print("published:" + info['year'])
    #     print("link: " + info['ee'])
    #     # print("author: " )
    #     # print(str())
    #     formatted_authors = ';'.join([author['text'] + '' for author in info['authors']['author']]) + ';'
    #     print("author: " + formatted_authors)
    #     print("summary: " + get_paper_abstract(info['title']))
    #     time.sleep(1)
    #     break
    # logging.info("done")
    # logging.warning("warning")
    # logging.error("error")
    # soup = BeautifulSoup(response.content, 'html.parser')
    # 找到导出链接中以 .json 结尾的链接
    # json_link = None
    # for a in soup.select("a[href$='format=json']"):
    #     if 'export' in a.get('href'):
    #         json_link = a.get('href')
    #         break
    #
    # # 如果找到链接，请求 JSON 内容
    # if json_link:
    #     full_url = json_link if json_link.startswith("http") else "https://dblp.org" + json_link
    #     json_resp = requests.get(full_url)
    #     json_data = json_resp.json()
    #
    #     # 输出示例：展示第一篇论文的标题
    #     for i, hit in enumerate(json_data["result"]["hits"]["hit"][:5]):
    #         print(f"{i+1}. {hit['info']['title']}")
    # else:
    #     print("未找到 JSON 导出链接")